package com.aliyun.messagemgt.controller;

import com.aliyun.messagemgt.application.service.ChannelService;
import com.aliyun.messagemgt.application.service.OperateLogService;
import com.aliyun.messagemgt.dto.PushChannelAdd;
import com.aliyun.messagemgt.dto.PushChannelList;
import com.aliyun.messagemgt.dto.query.PushChannelQuery;
import com.aliyun.messagemgt.web.controller.ChannelController;
import com.github.pagehelper.PageInfo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.web.servlet.MockMvc;

/**
 * @author wenyaxin
 * @date 2020/12/2
 */
@RunWith(MockitoJUnitRunner.class)
public class ChannelControllerTest {

    @InjectMocks
    private ChannelController channelController;

    @Mock
    private ChannelService channelService;

    @Mock
    private OperateLogService operateLogService;

    private MockMvc mockMvc;


    @Test
    @Rollback()
    public void saveChannelTest(){

        Mockito.when(channelService.detailChannel(Mockito.any())).thenReturn(createPushChannelList());
        Mockito.when(channelService.modPushChannel(Mockito.any())).thenReturn(1);
        Mockito.when(operateLogService.insertOperateLog(Mockito.any())).thenReturn(1);
        channelController.saveChannel(createPushChannelAdd());
    }

    @Test
    @Rollback()
    public void commitChannelTest(){
        Mockito.when(channelService.detailChannel(Mockito.any())).thenReturn(createPushChannelList());
        Mockito.when(channelService.modPushChannel(Mockito.any())).thenReturn(1);
        Mockito.when(operateLogService.insertOperateLog(Mockito.any())).thenReturn(1);
        channelController.commitChannel(createPushChannelAdd());
    }

    @Test
    @Rollback()
    public void listChannelTest(){
        Mockito.when(channelService.listPushChannel(Mockito.any())).thenReturn(new PageInfo<PushChannelList>());
        channelController.listChannel(createPushChannelQuery());
    }

    @Test
    @Rollback()
    public void topChannelTest(){
        Mockito.when(channelService.topChannel(Mockito.any())).thenReturn(1);
        channelController.topChannel(createPushChannelQuery());
    }

    @Test
    @Rollback()
    public void detailChannelTest(){
        Mockito.when(channelService.detailChannel(Mockito.any())).thenReturn(1);
        channelController.detailChannel(createPushChannelQuery());
    }

    @Test
    @Rollback()
    public void channelsTypesTest(){
        Mockito.when(channelService.channelsTypes(Mockito.any())).thenReturn(1);
        channelController.channelsTypes(createPushChannelQuery());
    }


    private PushChannelAdd createPushChannelAdd(){
        PushChannelAdd pushChannelAdd = new PushChannelAdd();
        pushChannelAdd.setDescription("1");
        pushChannelAdd.setPushChannelId(1L);
        pushChannelAdd.setUserId("1");
        pushChannelAdd.setUserName("1");
        pushChannelAdd.setDepartment("1");
        pushChannelAdd.setDepartmentName("1");
        return pushChannelAdd;
    }

    private PushChannelQuery createPushChannelQuery(){
        PushChannelQuery pushChannelQuery = new PushChannelQuery();
        pushChannelQuery.setUserId("1");
        pushChannelQuery.setUserName("1");
        pushChannelQuery.setDepartment("1");
        pushChannelQuery.setDepartmentName("1");
        pushChannelQuery.setPushChannelId(1L);
        return pushChannelQuery;
    }

    private PushChannelList createPushChannelList(){
        PushChannelList pushChannelList = new PushChannelList();
        pushChannelList.setDescription("1");
        return pushChannelList;
    }

}
